<%@page contentType="text/html" pageEncoding="UTF-8" import="org.bsscheduler.*"%>
<jsp:useBean id="user" class="org.bsscheduler.User" scope="session" />
<%
//if logged in, go to user's main page
if (user.getLoggedIn()) {%>
        <jsp:forward page="main.jsp" />
<%
}

String username = request.getParameter("username");
String password = request.getParameter("password");

// If username or password is not set, go to login page
if (username == null || password == null) {%>
<jsp:forward page="index.jsp" />
<%}

// If login is invalid, go to login page and show bad login message
if(!UsersDB.checkLogin(user, username, password)) {%>
<jsp:forward page="index.jsp?action=badlogin" />
<%
}
%>

<%-- login must have validated ok, go to user's main page --%>
<jsp:forward page="main.jsp" />
